package com.toutou.base.bindhelper

import android.R
import android.graphics.Color
import androidx.databinding.BindingAdapter
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener
import com.scwang.smart.refresh.layout.listener.OnRefreshListener

class SmartRefreshBDAdapter {
    companion object{
        @JvmStatic
        @BindingAdapter(value = ["refreshListener"], requireAll = false)
        fun setOnRefresh(view: SmartRefreshLayout, refreshListener: OnRefreshListener?) {
            if (refreshListener == null) {
                return
            }
            view.setEnableRefresh(true)
            view.setOnRefreshListener(refreshListener)
        }
        @JvmStatic
        @BindingAdapter("loadMoreListener")
        fun setOnLoadMore(view: SmartRefreshLayout, loadMoreListener: OnLoadMoreListener?) {
            if (loadMoreListener == null) {
                return
            }
            view.setOnLoadMoreListener (loadMoreListener)
        }

        @JvmStatic
        @BindingAdapter("refreshing")
        fun setRefreshing(view: SmartRefreshLayout, refreshing: Boolean) {
            if(!refreshing){
                view.finishRefresh()
                view.finishLoadMore()
            }
        }

        @JvmStatic
        @BindingAdapter("loadMoreEnable")
        fun setLoadMoreEnable(view: SmartRefreshLayout, loadMoreEnable: Boolean) {
            view.setEnableLoadMore(loadMoreEnable)
        }
        @JvmStatic
        @BindingAdapter("refreshEnable")
        fun setRefreshEnable(view: SmartRefreshLayout, refreshEnable: Boolean) {
            view.setEnableRefresh(refreshEnable)
        }
    }
}